package listados;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Vector;
import javax.swing.BorderFactory;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.table.DefaultTableModel;

import accesoADatos.AccesoADatos;

import paneles.JPanelConFondo;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public abstract class ListadoDialog extends javax.swing.JDialog {

	private static final long serialVersionUID = 1L;
	@SuppressWarnings("unchecked")
	private Vector v=new Vector();

	protected PaneListados paneListados1;
	protected JPanel jPanel1;

	public ListadoDialog(JFrame frame,Vector v) {
		super(frame);
		this.v=v;
		initGUI();
	}
	
	private void initGUI() {
		try {
			BorderLayout thisLayout = new BorderLayout();
			getContentPane().setLayout(thisLayout);
			{
				jPanel1 = new JPanelConFondo();
				FlowLayout jPanel1Layout = new FlowLayout();
				jPanel1Layout.setVgap(10);
				jPanel1Layout.setHgap(10);
				jPanel1.setLayout(jPanel1Layout);
				getContentPane().add(jPanel1, BorderLayout.CENTER);
				jPanel1.setPreferredSize(new java.awt.Dimension(602, 89));
			}
			{	
			
			paneListados1 = new PaneListados(v);
			FlowLayout paneListados1Layout = new FlowLayout();
			paneListados1Layout.setVgap(10);
			paneListados1Layout.setHgap(20);
			paneListados1.setLayout(paneListados1Layout);
			getContentPane().add(paneListados1, BorderLayout.SOUTH);
			paneListados1.setPreferredSize(new java.awt.Dimension(602, 370));
			paneListados1.getJTable1().setPreferredSize(new java.awt.Dimension(400, 300));
			paneListados1.getJTable1().setEnabled(false);
			paneListados1.getJTable1().setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(0,0,0)));
			paneListados1.getJButton1().addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent evt) {
					jButton1ActionPerformed(evt);
				}
			});
			}
			//pack();
			this.setSize(650, 520);
			pack();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	protected void jButton1ActionPerformed(ActionEvent evt) {
		this.paneListados1.borrarTabla();
		List l = getLista();
		for (int i=0;i<l.size(); i++){
			Vector v=cargarVector(l.get(i));
			((DefaultTableModel) (this.paneListados1.getJTable1().getModel())).addRow(v);
		}
		this.paneListados1.getJTable1().setPreferredSize(new Dimension(this.paneListados1.getJTable1().getWidth(),this.paneListados1.getJTable1().getRowCount()*this.paneListados1.getJTable1().getRowHeight(0)));
		AccesoADatos.getInstance().getSession().close();
	}

	public abstract Vector cargarVector(Object object);

	public abstract List getLista();
	
	public static String FormatearFecha(Date d){
		SimpleDateFormat s = new SimpleDateFormat("dd/MM/yyyy '-' HH':'mm");
		return (s.format(d));
	}

}
